package com.lv7.core.util.encrypt;

import java.util.Base64;

public class Base64Utils {

	/**
	 * 对字符串进行base64加密
	 * 
	 * @param str
	 * @return
	 */
	public static String encode(String str) {
		String base64 = null;
		if (str != null) {
			base64 = Base64.getEncoder().encodeToString(str.getBytes());
		}
		return base64;
	}

	/**
	 * 对base64的字符串进行解密
	 * 
	 * @param base64
	 * @return
	 */
	public static String decode(String base64) {
		String str = null;
		try {
			if (base64 != null) {
				str = new String(Base64.getDecoder().decode(base64));
			}
			return str;
		} catch (Exception e) {
			return base64;
		}
	}
}
